// miniprogram/pages/bmrs/bmrs.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    eduList: ['莱芜区', '钢城区', '济阳区','商河县','平阴县','槐荫区','天桥区','历城区'],
    minzuList: ['汉族', '回族', '满族','其他'],
    mianmaoList: ['党员','团员','民主党派','无党派','群众'],
    fixed:1,
    display:'',
    page:68
  },
  showview: function() { 
    this.setData({
      display: "block"
    })
  },
  hideview: function() {
    this.setData({
      display: "none"
    })
  },
  bindKeyInput: function(e) {
    this.setData({
      inputValue: e.detail.value
    })
  },
  //点击选择-省份地市
  choisezhuguanbumen() {
    var that = this;
    that.setData({
      bindpro: 1,
    })
  },
  //点击选择-学历edu
  choiseEdu() {
    var that = this;
    that.setData({
      bindedu: 1,
    })
  },
    //点击选择-民族
    choiseMinzu() {
      var that = this;
      that.setData({
        bindminzu: 1,
      })
    },
        //点击选择-政治面貌
        choiseMianmao() {
          var that = this;
          that.setData({
            bindmianmao: 1,
          })
        },
  //点击选择-学历edu
  setedu(e) {
    var that = this;
    console.log(e.currentTarget.dataset.quxian)
    that.setData({
      quxian: e.currentTarget.dataset.quxian,
      bindedu: !1
    })
  },
    //点击选择-民族
    choiseminzu() {
      var that = this;
      that.setData({
        bindminzu: 1,
      })
    },
    //点击选择-民族
    setminzu(e) {
      var that = this;
      console.log(e.currentTarget.dataset)
      that.setData({
        minzu: e.currentTarget.dataset.quxian,
        bindminzu: !1
      })
    },
        //点击选择-政治面貌
        setmianmao(e) {
          var that = this;
          console.log(e.currentTarget.dataset)
          that.setData({
            mianmao: e.currentTarget.dataset.quxian,
            bindmianmao: !1
          })
        },
        quchong(arr){
          console.log(arr)
          var tempArr = []; //返回的值
          var indexArr= []; //返回的索引
            for (var i = 0; i < arr.length; i++) {
              if (tempArr.indexOf(arr[i]) == -1) {
                tempArr.push(arr[i]);
                indexArr.push(i)
              } else if (tempArr.indexOf(arr[i])>=0){
                for(var j = 0;j<tempArr.length;j++){
                if (tempArr[j] == arr[i]) {
                  tempArr.splice(j, 1, tempArr[j]);
                  indexArr.splice(j, 1, i);
                }
              }
            }
          }
          return tempArr
        },

  //gangwei
  choisegangweimingcheng() {
    var that = this;
    if (that.data.quxian) {
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=42230&callback=?', //接收url
        data: {
          quxian: that.data.quxian,
          limits:500
          // onetext: that.data.zhuguanbumen
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          var list = [];
          for (var i in theJson.lists) { //循环写入下来框
            list.push(theJson.lists[i].danweiming)
          }
          console.log(list)
          that.setData({
            gangweimingchengList: that.quchong(list),
            bindgangweimingcheng: 1
          });
        }
      })
    } else {
      wx.showToast({
        title: '请先选择区县',
        icon: 'none'
      })
    }

  },
  choisegangwei() {
    var that = this;
    if (that.data.gangweimingcheng) {
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=42230&callback=?', //接收url
        data: {
          quxian: that.data.quxian,
          danweiming: that.data.gangweimingcheng,
          // onetext: that.data.zhuguanbumen
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          var listt = [];
          for (var i in theJson.lists) { //循环写入下来框
            listt.push(theJson.lists[i].zhiweiming)
          }
         
          that.setData({
            gangweiList: that.quchong(listt),
            bindgangwei: 1
          });
        }
      })
    } else {
      wx.showToast({
        title: '请先选择单位',
        icon: 'none'
      })
    }

  },
  //点击选择-政治面貌gangweimingcheng
  setgangweimingcheng(e) {
    var that = this;
    console.log(e.currentTarget.dataset.gangweimingcheng)
    that.setData({
      gangweimingcheng: e.currentTarget.dataset.gangweimingcheng,
      bindgangweimingcheng: !1,
      
    })
  },
  setgangwei(e) {
    var that = this;
    console.log(e)
    console.log(e.currentTarget.dataset.gangweimingcheng)
    that.setData({
      gangwei: e.currentTarget.dataset.gangweimingcheng,
      bindgangwei: !1
    })
  },


  closeselect() {
    var that = this;
    that.setData({
      bindEdu: !1,
      bindgangweimingcheng: !1,
    })
  },
  //个人信息查询提交
  submit() {
    var that = this;
    var phone = wx.getStorageSync('bmrsphone')
    if (phone) {
      if (that.data.quxian && that.data.gangweimingcheng) {
        wx.request({ //发送请求
          url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=42230&callback=?', //接收url
          data: {
            phone: phone,
            limits: 500,
            zhuguanbumen: that.data.zhuguanbumen,
            quxian: that.data.quxian,
            gangweimingcheng: that.data.gangweimingcheng
          }, //接收参数
          success(res) { //返回
            var jsonStr = res.data;
            jsonStr = jsonStr.replace("(", "");
            jsonStr = jsonStr.replace(")", "");
            if (typeof jsonStr != 'object') {
              jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
              var theJson = JSON.parse(jsonStr);
            }
            console.log(theJson)
           that.setData({
             lists:theJson.lists
           })
           wx.pageScrollTo({
            scrollTop: 300,
            duration: 600
          });
           
          }
        })
      } else {
        wx.showToast({
          title: '请完整填写信息',
          duration: 2000,
          icon: 'none'
        })
      }

    } else {
      wx.showToast({
        title: '请先登录',
        duration: 2000,
        icon: 'none'
      })
      that.setData({
        fixed: 1
      })
    }
  },
  getPhoneNumber(e) {
    var that = this;
    var fenxiao = that.data.area;
    var geneal = that.data.geneal;
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      wx.setStorageSync('zycxphone', res.result)
      console.log(res.result)
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/biaodan/register?actid=37634&callback=?', //接收url
        data: {
          phone: res.result,
          fenxiao: fenxiao,
          geneal: geneal,
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          that.setData({
            fixed: !1
          })
        }
      })

      wx.request({
        url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
        method: 'POST',
        data: {
          activeId: 32,
          mobile: res.result,
          areaCode: that.data.area,
          agent: that.data.geneal,
          pageId: that.data.page
        },
        success: res => {
          console.log(res);
        }
      })
    }).catch(err => {
      console.error(err);
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var phone = wx.getStorageSync('zycxphone')
    if(phone){
      that.setData({
        fixed:!1
      })
    }
    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent
    })
    if (options.page) {
      that.setData({
        page: options.page
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  searchList(event) {
    var that = this;
    var inputVal = (event.detail.value).replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
    console.log(inputVal)
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=36592&callback=?', //接收url
      data: {
        xueli: that.data.quxian,
        danweimingcheng: inputVal,
        limits: 500
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        console.log(theJson)

        that.setData({
          search_res: theJson.lists
        })
        // for (var i in theJson.lists) { //循环写入下来框
        //   list.push(theJson.lists[i].danweimingcheng)
        // }
        // console.log(list)
      }
    })
  },
  bindsearch(e) {
    console.log(e.currentTarget.dataset.set)
    var a = e.currentTarget.dataset.set
    var that = this;
    that.setData({
      danweimingcheng: a.danweimingcheng,
      zhuanyeleibie: a.zhuanyeleibie,
      danweimingcheng: a.danweimingcheng,
      bindmajor: !1,
      search_res: ''
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})